package cn.sdack.go.common.entities;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * User: sdake
 * Date: 2019/2/1
 */
public class JpaPage<T>  {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    //当前页
    public int page;
    //每页的数量
    public int pageSize;
    //总记录数
    public long totalSize;
    //总页数
    public int totalPages;
    //结果集
    public List<T> content;

    public static JpaPage getInstance() {
        return Holder.INSTANCE;
    }

    public static class Holder {
        public static final JpaPage INSTANCE = new JpaPage();
    }

    public static JpaPage to(Page page) {
        JpaPage instance = getInstance();
        instance.content = page.getContent();
        instance.page = page.getNumber() + 1;
        instance.pageSize = page.getSize();
        instance.totalPages = page.getTotalPages();
        instance.totalSize = page.getTotalElements();
        return instance;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public List<T> getContent() {
        return content;
    }

    public void setContent(List<T> content) {
        this.content = content;
    }
}
